;
//imgs:图片数组  options: each 和complete方法
var imgload = function (imgs,options){
	var defaults ={
		each: null, 
		complete: null 
	};
	settings = $.extend({},defaults,options);
	var loaded = [];
	var sum = imgs.length;
	//i：图片索引  imgSrc：图片路径
	$.each(imgs,function(i,imgSrc){
		var img = new Image();
		var url = imgSrc;
		var img_obj = img;
		$(img).bind('load error', function(e){
			loaded.push(img_obj);
			$.data(img_obj, 'loaded', ('error'==e.type)?false:true);
			settings.each.call(img_obj, loaded.slice(0),sum);
			if (loaded.length>=imgs.length ){ 
				settings.complete.call(loaded); 
			}
			$(this).unbind('load error');
		});
		//
		img.src = url;
	});
};
var imgs_init = [
	'./images/page-4.jpg',
	'./images/page-1.jpg',
	'./images/page-2.jpg',
	'./images/page-1-ani.jpg',
	'./images/logo.png',
	'./images/2017.png',
	'./images/jobs-1.png',
	'./images/jobs-2.png',
	'./images/jobs-3.png',
	'./images/jobs-4.png',
	'./images/jobs-5.png',
	'./images/jobs-6.png'
];

var img_preload = [

	'./images/page-3.jpg',
	'./images/slogan-1.png',
	'./images/type.png',
	'./images/paper.png',
	'./images/question.png',
	'./images/arrows.png',
	'./images/question-title.png',
	'./images/map.png',
	'./images/check.png',
	'./images/answer.png',
	'./images/100.png',
	'./images/80.png',
	'./images/60.png',
	'./images/100.png',
	'./images/bg-4.png',
	'./images/process-1.png',
	'./images/process-2.png',
	'./images/process-3.png',
	'./images/process-4.png',
	'./images/process-5.png',
	'./images/process-6.png',
	'./images/msg-1.png',
	'./images/msg-2.png',
	'./images/msg-3.png',
	'./images/phone.png',
	'./images/music_off.png',
	'./images/music_on.png',
	'./images/icon_audio_sign.png'
];

imgload(imgs_init,{
	each:function(e,sum){
		var per = parseInt((e.length / sum)*100) + '%';
		$('.percent').text(per);
		$('.bar-progress').css('width',per);
	},
	//加载完成
	complete:function(){
        $(function () {
            $('#loading').fadeOut(1000);
            //1.图片加载
            //2.字体加载
            //var upright = new Font();
            var autoMusic = true;
            //2.加载音乐
            var music = $('<audio  loop="true" autoplay style="width:0;height:0" id="audio-music">')[0];
            $('body').append(music);
            music.src = './audio/music.mp3';
            music.oncanplay  = function () {
				$('.audio-loading').hide();
            }
            audio();
            $('body').bind('touchend', function () {
                if (autoMusic) {
                    $('audio')[0].play();
                    $('.icon_audio').addClass('border_anim');
                    $('.icon_audio').removeClass('off-1');
                    autoMusic = false;
                }
            })
        })
	}
})

//
// imgload(img_preload,{
// 	each : function (e,i) {
//
// 	},
// 	complete : function () {
//
// 	}
// });

